import router from "#/router";

const state = {
    isCollapse: new Boolean(),
    isLogin: true,
    iframeViews: [],
    path: {},
    active: new Object(),
}

const mutations = {
    IS_COLLAPSE: (state, value) => {
        if (value !== null && value !== "") {
            state.isCollapse = value;
        }
    },
    IS_LOGIN: (state, value) => {
        if (value !== null && value !== "") {
            state.isLogin = value;
        }
    },
    SET_PATH: (state, value) => {
        if (value !== null && value !== "") {
            state.path = value;
        }
    },
    SET_ACTIVE: (state, value) => {
        if (value !== null && value !== "") {
            state.active = value;
        }
    },
    TO: (state, value) => {
        if (value !== null && value !== "") {
            state.active = value;
            if (state.iframeViews.filter(e => e.id === value.id).length === 0) {
                state.iframeViews.push(value);
            }
            router.push({path: value.path});
        }
    },
    RM: (state, value) => {
        if (value !== null && value !== "") {
            state.iframeViews = state.iframeViews.filter(e => e.id === value.id);
            console.log(state.iframeViews);
        }
    }
}


const actions = {
    // 设置menu显隐
    isCollapse({commit}, data) {
        commit('IS_COLLAPSE', data)
    },
    //设置登陆状态
    isLogin({commit}, data) {
        commit('IS_LOGIN', data)
    },
    //设置登陆状态
    setPath({commit}, data) {
        commit('SET_PATH', data)
    },

    setActive({commit}, data) {
        commit('SET_ACTIVE', data)
    },
    to({commit}, data) {
        commit('TO', data)
    },
    rm({commit}, data) {
        commit('RM', data)
    },
}

export default {
    namespaced: true,
    state,
    mutations,
    actions
}